package com.cxhome.cxinfox.QCellCore;

import java.util.List;

import org.apache.log4j.Logger;

import com.jfinal.aop.Clear;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.traffic.managent.base.BaseService;

/**
 * 省份获取
 * 
 */
public class ProvinceService extends BaseService {

	private final static Logger log = Logger.getLogger(ProvinceService.class);
	public static final ProvinceService service = new ProvinceService();

	/**
	 * 
	 * 省份下拉框
	 * 
	 * @return
	 */
	@Clear
	public String selectProvince(String selected) {

		String sql = "SELECT '1000' AS province_id, '全国' AS province_name FROM DUAL " + "UNION ALL "
				+ "SELECT province_id, province_name FROM (SELECT DISTINCT province AS province_id,provinceName AS province_name FROM cx_phone_head ORDER BY province ) a";

		List<Record> list = Db.find(sql);

		StringBuffer sb = new StringBuffer("");

		if (list != null && list.size() > 0) {
			for (Record providerinfo : list) {
				sb.append("<option value=\"");
				sb.append(providerinfo.getStr("province_id"));
				sb.append("\" ");
				sb.append((selected != null && providerinfo.getStr("province_id").equals(selected)) ? "selected" : "");
				sb.append(">");
				sb.append(providerinfo.getStr("province_name"));
				sb.append("</option>");
			}
		}
		return sb.toString();
	}

}
